/*
 * SysUtil.h
 *
 *  Created on: 2011-7-9
 *      Author: gexiao
 */
/*
 * System utilities
 */
#ifndef SYSUTIL_H_
#define SYSUTIL_H_
#include <sys/types.h>

/*
 * System page size.  Normally you're expected to get this from
 * sysconf(_SC_PAGESIZE) or some system-specific define (usually PAGESIZE
 * or PAGE_SIZE).  If we use a simple #define the compiler can generate
 * appropriate masks directly, so we define it here and verify it as the
 * VM is starting up.
 *
 * Must be a power of 2.
 */
#define SYSTEM_PAGE_SIZE        4096

/*
 * Use this to keep track of mapped segments.
 */
typedef struct MemMapping {
	void* addr; //start of data
	size_t length; //length of data

	void* baseAddr; //page-aligned base address
	size_t baseLength;//length of mapping
} MemMapping;

/*
 * Copy a map.
 */
void sysCopyMap(MemMapping* dst, const MemMapping* src);

/*
 * Like sysMapFileInShmemReadOnly, but on only part of a file.
 */
int sysMapFileSegmentInShmem(int fd, off_t start, size_t length,
    MemMapping* pMap);

/*
 * Release the pages associated with a shared memory segment.
 *
 * This does not free "pMap"; it just releases the memory.
 */
void sysReleaseShmem(MemMapping* pMap);
#endif /* SYSUTIL_H_ */
